package com.feiyu.shopsAndgoods.controller;

import java.util.*;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.feiyu.shopsAndgoods.entity.CheckGoodsEntity;
import com.feiyu.shopsAndgoods.entity.DictGoodsEntity;
import com.feiyu.shopsAndgoods.entity.ShopEntity;
import com.feiyu.shopsAndgoods.service.CheckGoodsService;
import com.feiyu.shopsAndgoods.service.DictGoodsService;
import com.feiyu.shopsAndgoods.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.feiyu.shopsAndgoods.entity.GoodsEntity;
import com.feiyu.shopsAndgoods.service.GoodsService;
import com.feiyu.common.utils.PageUtils;
import com.feiyu.common.utils.R;


/**
 * @author wanghanbin
 * @email 1336891708@qq.com
 * @date 2021-04-03 12:36:05
 */
@RestController
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @Autowired
    private DictGoodsService dictGoodsService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private CheckGoodsService checkGoodsService;

    /**
     * 商城首页展示推荐商品
     */
    @PostMapping("/openFeiyu/recommendGoods")
    public R recommendGoods(@RequestBody Map<String, Object> params) {
        int recommendGoodsNumber = (int) params.get("recommendGoodsNumber");
        if (recommendGoodsNumber <= 0) {
            return R.error("操作失败").put("data", null);
        }
        List<GoodsEntity> recommendGoods = goodsService.getRecommendGoodsByNum(recommendGoodsNumber);
        if (recommendGoods.size() == 0) {
            return R.error("商品表暂无商品").put("data", null);
        }
        List<Map<String, Object>> recommendGoodsList = new ArrayList<>();
        for (GoodsEntity recommendGood : recommendGoods) {
            HashMap<String, Object> recommendGoodInfo = new HashMap<>();
            HashMap<String, Object> recommendGoodInfoImages = new HashMap<>();
            String goodsImages = recommendGood.getGoodsImages();
            String[] split = goodsImages.split(";");
            String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
            for (int i = 0; i < split.length; i++) {
                recommendGoodInfoImages.put("goodImage_" + (i + 1), url + split[i]);
            }
            Integer goodsTagId = recommendGood.getGoodsTagId();
            DictGoodsEntity tag = dictGoodsService.getById(goodsTagId);
            Integer shopId = recommendGood.getShopId();
            ShopEntity shopEntity = shopService.getById(shopId);
            recommendGoodInfo.put("goodsId", recommendGood.getGoodsId());
            recommendGoodInfo.put("goodsName", recommendGood.getGoodsName());
            recommendGoodInfo.put("goodsIntro", recommendGood.getGoodsIntro());
            recommendGoodInfo.put("shopId", recommendGood.getShopId());
            recommendGoodInfo.put("shopName", shopEntity.getShopName());
            recommendGoodInfo.put("goodsImages", recommendGoodInfoImages);
            recommendGoodInfo.put("goodsLicense", recommendGood.getGoodsLicense());
            recommendGoodInfo.put("goodsRent", recommendGood.getGoodsRent());
            recommendGoodInfo.put("goodsDeposit", recommendGood.getGoodsDeposit());
            recommendGoodInfo.put("goodsPrice", recommendGood.getGoodsPrice());
            recommendGoodInfo.put("goodsTagId", recommendGood.getGoodsTagId());
            recommendGoodInfo.put("goodsTagName", tag.getDictGoodsLable());
            recommendGoodInfo.put("goodsTimeMode", recommendGood.getGoodsTimeMode());
            recommendGoodInfo.put("isAllowedBuy", recommendGood.getIsAllowedBuy());
            recommendGoodInfo.put("goodsPostageMode", recommendGood.getGoodsPostageMode());
            recommendGoodInfo.put("goodsMaxRenewalTime", recommendGood.getGoodsMaxRenewalTime());
            recommendGoodInfo.put("goodsNums", recommendGood.getGoodsNums());
            recommendGoodInfo.put("goodsState", recommendGood.getGoodsState());
            recommendGoodsList.add(recommendGoodInfo);
        }
        return R.ok("操作成功").put("data", recommendGoodsList);
    }

    /**
     * 商城搜索商品标签模糊查找商品
     */
    @RequestMapping("/openFeiyu/searchGoodsByTagName")
    public R searchGoodsByTagName(@RequestBody Map<String, Object> params) {
        String goodsTagName = (String) params.get("goodsTagName");
        List<DictGoodsEntity> dictGoodsEntities = dictGoodsService.getByDictGoodsLable(goodsTagName);
        if (dictGoodsEntities.size() == 0) {
            return R.error("无该标签商品").put("data", null);
        }
        List<Integer> goodsTagId = new ArrayList<>();
        for (DictGoodsEntity dictGoodsEntity : dictGoodsEntities) {
            goodsTagId.add(dictGoodsEntity.getDictGoodsId());
        }
        params.put("goodsTagId", goodsTagId);
        PageUtils page = goodsService.queryPageByGoodTagName(params);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("totalCount", page.getTotalCount());
        hashMap.put("pageSize", page.getPageSize());
        hashMap.put("totalPage", page.getTotalPage());
        hashMap.put("currPage", page.getCurrPage());
        List<?> pageList = page.getList();
        List<Map<String, Object>> goodInfo_list = new ArrayList<>();
        for (int i = 0; i < pageList.size(); i++) {
            HashMap<String, Object> goodInfoImages = new HashMap<>();
            HashMap<String, Object> goodsInfo = new HashMap<>();
            GoodsEntity goodsEntity = (GoodsEntity) pageList.get(i);
            String goodsImages = goodsEntity.getGoodsImages();
            String[] split = goodsImages.split(";");
            String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
            for (int j = 0; j < split.length; j++) {
                goodInfoImages.put("goodImage_" + (j + 1), url + split[j]);
            }
            Integer tagId = goodsEntity.getGoodsTagId();
            DictGoodsEntity tag = dictGoodsService.getById(tagId);
            Integer shopId = goodsEntity.getShopId();
            ShopEntity shopEntity = shopService.getById(shopId);
            goodsInfo.put("goodsId", goodsEntity.getGoodsId());
            goodsInfo.put("goodsName", goodsEntity.getGoodsName());
            goodsInfo.put("goodsIntro", goodsEntity.getGoodsIntro());
            goodsInfo.put("shopId", goodsEntity.getShopId());
            goodsInfo.put("shopName", shopEntity.getShopName());
            goodsInfo.put("goodsImages", goodInfoImages);
            goodsInfo.put("goodsLicense", goodsEntity.getGoodsLicense());
            goodsInfo.put("goodsRent", goodsEntity.getGoodsRent());
            goodsInfo.put("goodsDeposit", goodsEntity.getGoodsDeposit());
            goodsInfo.put("goodsPrice", goodsEntity.getGoodsPrice());
            goodsInfo.put("goodsTagId", goodsEntity.getGoodsTagId());
            goodsInfo.put("goodsTagName", tag.getDictGoodsLable());
            goodsInfo.put("goodsTimeMode", goodsEntity.getGoodsTimeMode());
            goodsInfo.put("isAllowedBuy", goodsEntity.getIsAllowedBuy());
            goodsInfo.put("goodsPostageMode", goodsEntity.getGoodsPostageMode());
            goodsInfo.put("goodsMaxRenewalTime", goodsEntity.getGoodsMaxRenewalTime());
            goodsInfo.put("goodsNums", goodsEntity.getGoodsNums());
            goodsInfo.put("goodsState", goodsEntity.getGoodsState());
            goodInfo_list.add(goodsInfo);
        }
        hashMap.put("list", goodInfo_list);
        return R.ok("操作成功").put("data", hashMap);
    }

    /**
     * 商城搜索商品标签精确查找商品
     */
    @PostMapping("/openFeiyu/searchGoodsByTagId")
    public R searchGoodsByTagId(@RequestBody Map<String, Object> params) {
        PageUtils page = goodsService.queryPageByTagId(params);
        if (page.getList().size() == 0) {
            return R.error("未查询到相关标签商品").put("data", null);
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("totalCount", page.getTotalCount());
        hashMap.put("pageSize", page.getPageSize());
        hashMap.put("totalPage", page.getTotalPage());
        hashMap.put("currPage", page.getCurrPage());
        List<?> pageList = page.getList();
        List<Map<String, Object>> goodInfo_list = new ArrayList<>();
        for (int i = 0; i < pageList.size(); i++) {
            HashMap<String, Object> goodInfoImages = new HashMap<>();
            HashMap<String, Object> goodsInfo = new HashMap<>();
            GoodsEntity goodsEntity = (GoodsEntity) pageList.get(i);
            String goodsImages = goodsEntity.getGoodsImages();
            String[] split = goodsImages.split(";");
            String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
            for (int j = 0; j < split.length; j++) {
                goodInfoImages.put("goodImage_" + (j + 1), url + split[j]);
            }
            Integer tagId = goodsEntity.getGoodsTagId();
            DictGoodsEntity tag = dictGoodsService.getById(tagId);
            Integer shopId = goodsEntity.getShopId();
            ShopEntity shopEntity = shopService.getById(shopId);
            goodsInfo.put("goodsId", goodsEntity.getGoodsId());
            goodsInfo.put("goodsName", goodsEntity.getGoodsName());
            goodsInfo.put("goodsIntro", goodsEntity.getGoodsIntro());
            goodsInfo.put("shopId", goodsEntity.getShopId());
            goodsInfo.put("shopName", shopEntity.getShopName());
            goodsInfo.put("goodsImages", goodInfoImages);
            goodsInfo.put("goodsLicense", goodsEntity.getGoodsLicense());
            goodsInfo.put("goodsRent", goodsEntity.getGoodsRent());
            goodsInfo.put("goodsDeposit", goodsEntity.getGoodsDeposit());
            goodsInfo.put("goodsPrice", goodsEntity.getGoodsPrice());
            goodsInfo.put("goodsTagId", goodsEntity.getGoodsTagId());
            goodsInfo.put("goodsTagName", tag.getDictGoodsLable());
            goodsInfo.put("goodsTimeMode", goodsEntity.getGoodsTimeMode());
            goodsInfo.put("isAllowedBuy", goodsEntity.getIsAllowedBuy());
            goodsInfo.put("goodsPostageMode", goodsEntity.getGoodsPostageMode());
            goodsInfo.put("goodsMaxRenewalTime", goodsEntity.getGoodsMaxRenewalTime());
            goodsInfo.put("goodsNums", goodsEntity.getGoodsNums());
            goodsInfo.put("goodsState", goodsEntity.getGoodsState());
            goodInfo_list.add(goodsInfo);
        }
        hashMap.put("list", goodInfo_list);
        return R.ok("操作成功").put("data", hashMap);
    }

    /**
     * 商城搜索商品名模糊查找商品
     */
    @PostMapping("/openFeiyu/searchGoodsByGoodsName")
    public R searchGoodsByGoodsName(@RequestBody Map<String, Object> params) {
        PageUtils page = goodsService.queryPageByGoodsName(params);
        if (page.getList().size() == 0) {
            return R.error("未查询到相关商品名的商品").put("data", null);
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("totalCount", page.getTotalCount());
        hashMap.put("pageSize", page.getPageSize());
        hashMap.put("totalPage", page.getTotalPage());
        hashMap.put("currPage", page.getCurrPage());
        List<?> pageList = page.getList();
        List<Map<String, Object>> goodInfo_list = new ArrayList<>();
        for (int i = 0; i < pageList.size(); i++) {
            HashMap<String, Object> goodInfoImages = new HashMap<>();
            HashMap<String, Object> goodsInfo = new HashMap<>();
            GoodsEntity goodsEntity = (GoodsEntity) pageList.get(i);
            String goodsImages = goodsEntity.getGoodsImages();
            String[] split = goodsImages.split(";");
            String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
            for (int j = 0; j < split.length; j++) {
                goodInfoImages.put("goodImage_" + (j + 1), url + split[j]);
            }
            Integer tagId = goodsEntity.getGoodsTagId();
            DictGoodsEntity tag = dictGoodsService.getById(tagId);
            Integer shopId = goodsEntity.getShopId();
            ShopEntity shopEntity = shopService.getById(shopId);
            goodsInfo.put("goodsId", goodsEntity.getGoodsId());
            goodsInfo.put("goodsName", goodsEntity.getGoodsName());
            goodsInfo.put("goodsIntro", goodsEntity.getGoodsIntro());
            goodsInfo.put("shopId", goodsEntity.getShopId());
            goodsInfo.put("shopName", shopEntity.getShopName());
            goodsInfo.put("goodsImages", goodInfoImages);
            goodsInfo.put("goodsLicense", goodsEntity.getGoodsLicense());
            goodsInfo.put("goodsRent", goodsEntity.getGoodsRent());
            goodsInfo.put("goodsDeposit", goodsEntity.getGoodsDeposit());
            goodsInfo.put("goodsPrice", goodsEntity.getGoodsPrice());
            goodsInfo.put("goodsTagId", goodsEntity.getGoodsTagId());
            goodsInfo.put("goodsTagName", tag.getDictGoodsLable());
            goodsInfo.put("goodsTimeMode", goodsEntity.getGoodsTimeMode());
            goodsInfo.put("isAllowedBuy", goodsEntity.getIsAllowedBuy());
            goodsInfo.put("goodsPostageMode", goodsEntity.getGoodsPostageMode());
            goodsInfo.put("goodsMaxRenewalTime", goodsEntity.getGoodsMaxRenewalTime());
            goodsInfo.put("goodsNums", goodsEntity.getGoodsNums());
            goodsInfo.put("goodsState", goodsEntity.getGoodsState());
            goodInfo_list.add(goodsInfo);
        }
        hashMap.put("list", goodInfo_list);
        return R.ok("操作成功").put("data", hashMap);
    }

    /**
     * 商城精确查找商品
     */
    @PostMapping("/openFeiyu/searchGoodsByGoodId")
    public R searchGoodsByGoodId(@RequestBody GoodsEntity goodsEntity) {
        GoodsEntity goods = goodsService.getById(goodsEntity.getGoodsId());
        if (goods == null) {
            return R.error("未查询到对应商品").put("data", null);
        }
        HashMap<String, Object> goodsInfo = new HashMap<>();
        HashMap<String, Object> goodInfoImages = new HashMap<>();
        String goodsImages = goods.getGoodsImages();
        String[] split = goodsImages.split(";");
        String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
        for (int i = 0; i < split.length; i++) {
            goodInfoImages.put("goodImage_" + (i + 1), url + split[i]);
        }
        Integer tagId = goods.getGoodsTagId();
        DictGoodsEntity tag = dictGoodsService.getById(tagId);
        Integer shopId = goods.getShopId();
        ShopEntity shopEntity = shopService.getById(shopId);
        goodsInfo.put("goodsId", goods.getGoodsId());
        goodsInfo.put("goodsName", goods.getGoodsName());
        goodsInfo.put("goodsIntro", goods.getGoodsIntro());
        goodsInfo.put("shopId", goods.getShopId());
        goodsInfo.put("shopName", shopEntity.getShopName());
        goodsInfo.put("goodsImages", goodInfoImages);
        goodsInfo.put("goodsLicense", goods.getGoodsLicense());
        goodsInfo.put("goodsRent", goods.getGoodsRent());
        goodsInfo.put("goodsDeposit", goods.getGoodsDeposit());
        goodsInfo.put("goodsPrice", goods.getGoodsPrice());
        goodsInfo.put("goodsTagId", goods.getGoodsTagId());
        goodsInfo.put("goodsTagName", tag.getDictGoodsLable());
        goodsInfo.put("goodsTimeMode", goods.getGoodsTimeMode());
        goodsInfo.put("isAllowedBuy", goods.getIsAllowedBuy());
        goodsInfo.put("goodsPostageMode", goods.getGoodsPostageMode());
        goodsInfo.put("goodsMaxRenewalTime", goods.getGoodsMaxRenewalTime());
        goodsInfo.put("goodsNums", goods.getGoodsNums());
        goodsInfo.put("goodsState", goods.getGoodsState());
        return R.ok("操作成功").put("data", goodsInfo);
    }

    /**
     * 店铺后台查看全部商品
     */
    @PostMapping("/searchGoodsByShopId")
    public R searchGoodsByShopId(@RequestBody Map<String, Object> params) {
        PageUtils page = goodsService.queryPageByShopId(params);
        if (page.getList().size() == 0) {
            return R.error("未查询到该店铺的商品").put("data", null);
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("totalCount", page.getTotalCount());
        hashMap.put("pageSize", page.getPageSize());
        hashMap.put("totalPage", page.getTotalPage());
        hashMap.put("currPage", page.getCurrPage());
        List<?> pageList = page.getList();
        List<Map<String, Object>> goodInfo_list = new ArrayList<>();
        for (int i = 0; i < pageList.size(); i++) {
            HashMap<String, Object> goodInfoImages = new HashMap<>();
            HashMap<String, Object> goodsInfo = new HashMap<>();
            GoodsEntity goodsEntity = (GoodsEntity) pageList.get(i);
            String goodsImages = goodsEntity.getGoodsImages();
            String[] split = goodsImages.split(";");
            String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
            for (int j = 0; j < split.length; j++) {
                goodInfoImages.put("goodImage_" + (j + 1), url + split[j]);
            }
            Integer tagId = goodsEntity.getGoodsTagId();
            DictGoodsEntity tag = dictGoodsService.getById(tagId);
            Integer shopId = goodsEntity.getShopId();
            ShopEntity shopEntity = shopService.getById(shopId);
            goodsInfo.put("goodsId", goodsEntity.getGoodsId());
            goodsInfo.put("goodsName", goodsEntity.getGoodsName());
            goodsInfo.put("goodsIntro", goodsEntity.getGoodsIntro());
            goodsInfo.put("shopId", goodsEntity.getShopId());
            goodsInfo.put("shopName", shopEntity.getShopName());
            goodsInfo.put("goodsImages", goodInfoImages);
            goodsInfo.put("goodsLicense", goodsEntity.getGoodsLicense());
            goodsInfo.put("goodsRent", goodsEntity.getGoodsRent());
            goodsInfo.put("goodsDeposit", goodsEntity.getGoodsDeposit());
            goodsInfo.put("goodsPrice", goodsEntity.getGoodsPrice());
            goodsInfo.put("goodsTagId", goodsEntity.getGoodsTagId());
            goodsInfo.put("goodsTagName", tag.getDictGoodsLable());
            goodsInfo.put("goodsTimeMode", goodsEntity.getGoodsTimeMode());
            goodsInfo.put("isAllowedBuy", goodsEntity.getIsAllowedBuy());
            goodsInfo.put("goodsPostageMode", goodsEntity.getGoodsPostageMode());
            goodsInfo.put("goodsMaxRenewalTime", goodsEntity.getGoodsMaxRenewalTime());
            goodsInfo.put("goodsNums", goodsEntity.getGoodsNums());
            goodsInfo.put("goodsState", goodsEntity.getGoodsState());
            goodInfo_list.add(goodsInfo);
        }
        hashMap.put("list", goodInfo_list);
        return R.ok("操作成功").put("data", hashMap);
    }

    /**
     * 店铺后台精确查找商品
     */
    @PostMapping("/searchGoodsByGoodId")
    public R searchGoodsByGoodIdByShop(@RequestBody GoodsEntity goodsEntity){
        GoodsEntity goods = goodsService.getById(goodsEntity.getGoodsId());
        if (goods == null) {
            return R.error("未查询到对应商品").put("data", null);
        }
        HashMap<String, Object> goodsInfo = new HashMap<>();
        HashMap<String, Object> goodInfoImages = new HashMap<>();
        String goodsImages = goods.getGoodsImages();
        String[] split = goodsImages.split(";");
        String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
        for (int i = 0; i < split.length; i++) {
            goodInfoImages.put("goodImage_" + (i + 1), url + split[i]);
        }
        Integer tagId = goods.getGoodsTagId();
        DictGoodsEntity tag = dictGoodsService.getById(tagId);
        Integer shopId = goods.getShopId();
        ShopEntity shopEntity = shopService.getById(shopId);
        goodsInfo.put("goodsId", goods.getGoodsId());
        goodsInfo.put("goodsName", goods.getGoodsName());
        goodsInfo.put("goodsIntro", goods.getGoodsIntro());
        goodsInfo.put("shopId", goods.getShopId());
        goodsInfo.put("shopName", shopEntity.getShopName());
        goodsInfo.put("goodsImages", goodInfoImages);
        goodsInfo.put("goodsLicense", goods.getGoodsLicense());
        goodsInfo.put("goodsRent", goods.getGoodsRent());
        goodsInfo.put("goodsDeposit", goods.getGoodsDeposit());
        goodsInfo.put("goodsPrice", goods.getGoodsPrice());
        goodsInfo.put("goodsTagId", goods.getGoodsTagId());
        goodsInfo.put("goodsTagName", tag.getDictGoodsLable());
        goodsInfo.put("goodsTimeMode", goods.getGoodsTimeMode());
        goodsInfo.put("isAllowedBuy", goods.getIsAllowedBuy());
        goodsInfo.put("goodsPostageMode", goods.getGoodsPostageMode());
        goodsInfo.put("goodsMaxRenewalTime", goods.getGoodsMaxRenewalTime());
        goodsInfo.put("goodsNums", goods.getGoodsNums());
        goodsInfo.put("goodsState", goods.getGoodsState());
        return R.ok("操作成功").put("data", goodsInfo);
    }
    /**
     * 店铺后台上架商品
     */
    @PostMapping("/addGood")
    //@RequiresPermissions("product:goods:save")
    public R addGood(@RequestBody CheckGoodsEntity checkGoodsEntity) {
        String goodsImages = checkGoodsEntity.getGoodsImages();
        String[] split = goodsImages.split(";");
        String newGoodsImages = "";
        for (int i = 0; i < split.length; i++) {
            String substring = split[i].substring(65);
            if (i == (split.length - 1)) {
                newGoodsImages = newGoodsImages + substring;
            } else {
                newGoodsImages = newGoodsImages + substring + ";";
            }
        }
        checkGoodsEntity.setGoodsImages(newGoodsImages);
        GoodsEntity goodsEntity = new GoodsEntity();
        goodsEntity.setGoodsName(checkGoodsEntity.getGoodsName());
        goodsEntity.setGoodsIntro(checkGoodsEntity.getGoodsIntro());
        goodsEntity.setShopId(checkGoodsEntity.getShopId());
        goodsEntity.setGoodsImages(checkGoodsEntity.getGoodsImages());
        goodsEntity.setGoodsLicense(checkGoodsEntity.getGoodsLicense());
        goodsEntity.setGoodsRent(checkGoodsEntity.getGoodsRent());
        goodsEntity.setGoodsDeposit(checkGoodsEntity.getGoodsDeposit());
        goodsEntity.setGoodsPrice(checkGoodsEntity.getGoodsPrice());
        goodsEntity.setGoodsTagId(checkGoodsEntity.getGoodsTagId());
        goodsEntity.setGoodsTimeMode(checkGoodsEntity.getGoodsTimeMode());
        goodsEntity.setIsAllowedBuy(checkGoodsEntity.getIsAllowedBuy());
        goodsEntity.setGoodsPostageMode(checkGoodsEntity.getGoodsPostageMode());
        goodsEntity.setGoodsMaxRenewalTime(checkGoodsEntity.getGoodsMaxRenewalTime());
        goodsEntity.setGoodsNums(checkGoodsEntity.getGoodsNums());
        goodsService.save(goodsEntity);
        checkGoodsEntity.setGoodsId(goodsEntity.getGoodsId());
        checkGoodsService.save(checkGoodsEntity);
        HashMap<String, Object> data = new HashMap<>();
        data.put("goodsId", goodsEntity.getGoodsId());
        data.put("checkGoodsId", checkGoodsEntity.getCheckGoodsId());
        return R.ok("操作成功，商品正在审核中").put("data", data);
    }

    /**
     * 店铺后台修改上架商品
     */
    @PostMapping("/updateGoodById")
    public R updateGoodById(@RequestBody CheckGoodsEntity checkGoodsEntity) {
        String goodsImages = checkGoodsEntity.getGoodsImages();
        String[] split = goodsImages.split(";");
        String newGoodsImages = "";
        for (int i = 0; i < split.length; i++) {
            String substring = split[i].substring(65);
            if (i == (split.length - 1)) {
                newGoodsImages = newGoodsImages + substring;
            } else {
                newGoodsImages = newGoodsImages + substring + ";";
            }
        }
        checkGoodsEntity.setGoodsImages(newGoodsImages);
        checkGoodsService.save(checkGoodsEntity);
        return R.ok("操作成功").put("data", null);
    }

    /**
     * 店铺后台删除上架商品
     */
    @RequestMapping("/deleteGoodByGoodsId")
    public R deleteGoodByGoodsId(@RequestBody GoodsEntity goodsEntity) {
        goodsService.removeById(goodsEntity.getGoodsId());
        return R.ok("删除成功").put("data", null);
    }

    /**
     * 店铺后台查看全部审核商品
     */
    @PostMapping("/getAllReviewGoodsByShopId")
    public R getAllReviewGoodsByShopId(@RequestBody Map<String, Object> params) {
        PageUtils page = checkGoodsService.queryPageByShopId(params);
        if (page.getList().size() == 0) {
            return R.error("未查询到该店铺的审核商品").put("data", null);
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("totalCount", page.getTotalCount());
        hashMap.put("pageSize", page.getPageSize());
        hashMap.put("totalPage", page.getTotalPage());
        hashMap.put("currPage", page.getCurrPage());
        List<?> pageList = page.getList();
        List<Map<String, Object>> checkGoodInfo_list = new ArrayList<>();
        for (int i = 0; i < pageList.size(); i++) {
            HashMap<String, Object> checkGoodInfoImages = new HashMap<>();
            HashMap<String, Object> checkGoodsInfo = new HashMap<>();
            CheckGoodsEntity checkGoodsEntity = (CheckGoodsEntity) pageList.get(i);
            String checkGoodsImages = checkGoodsEntity.getGoodsImages();
            String[] split = checkGoodsImages.split(";");
            String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
            for (int j = 0; j < split.length; j++) {
                checkGoodInfoImages.put("goodImage_" + (j + 1), url + split[j]);
            }
            Integer tagId = checkGoodsEntity.getGoodsTagId();
            DictGoodsEntity tag = dictGoodsService.getById(tagId);
            Integer shopId = checkGoodsEntity.getShopId();
            ShopEntity shopEntity = shopService.getById(shopId);
            checkGoodsInfo.put("checkGoodsId", checkGoodsEntity.getCheckGoodsId());
            checkGoodsInfo.put("goodsId", checkGoodsEntity.getGoodsId());
            checkGoodsInfo.put("goodsName", checkGoodsEntity.getGoodsName());
            checkGoodsInfo.put("goodsIntro", checkGoodsEntity.getGoodsIntro());
            checkGoodsInfo.put("shopId", checkGoodsEntity.getShopId());
            checkGoodsInfo.put("shopName", shopEntity.getShopName());
            checkGoodsInfo.put("goodsImages", checkGoodInfoImages);
            checkGoodsInfo.put("goodsLicense", checkGoodsEntity.getGoodsLicense());
            checkGoodsInfo.put("goodsRent", checkGoodsEntity.getGoodsRent());
            checkGoodsInfo.put("goodsDeposit", checkGoodsEntity.getGoodsDeposit());
            checkGoodsInfo.put("goodsPrice", checkGoodsEntity.getGoodsPrice());
            checkGoodsInfo.put("goodsTagId", checkGoodsEntity.getGoodsTagId());
            checkGoodsInfo.put("goodsTagName", tag.getDictGoodsLable());
            checkGoodsInfo.put("goodsTimeMode", checkGoodsEntity.getGoodsTimeMode());
            checkGoodsInfo.put("isAllowedBuy", checkGoodsEntity.getIsAllowedBuy());
            checkGoodsInfo.put("goodsPostageMode", checkGoodsEntity.getGoodsPostageMode());
            checkGoodsInfo.put("goodsMaxRenewalTime", checkGoodsEntity.getGoodsMaxRenewalTime());
            checkGoodsInfo.put("goodsNums", checkGoodsEntity.getGoodsNums());
            checkGoodsInfo.put("checkGoodsApplyTime", checkGoodsEntity.getCheckGoodsApplyTime());
            checkGoodsInfo.put("checkState", checkGoodsEntity.getCheckState());
            checkGoodsInfo.put("checkUserId", checkGoodsEntity.getCheckUserId());
            checkGoodsInfo.put("checkTime", checkGoodsEntity.getCheckTime());
            checkGoodsInfo.put("checkRe", checkGoodsEntity.getCheckRe());
            checkGoodInfo_list.add(checkGoodsInfo);
        }
        hashMap.put("list", checkGoodInfo_list);
        return R.ok("操作成功").put("data", hashMap);
    }

    /**
     * 店铺后台精确查询审核商品
     */
    @PostMapping("/getReviewGoodByCheckGoodId")
    public R getReviewGoodByCheckGoodId(@RequestBody CheckGoodsEntity checkGoodsEntity) {
        CheckGoodsEntity entity = checkGoodsService.getById(checkGoodsEntity.getCheckGoodsId());
        if (entity == null) {
            return R.error("未查询到该审核商品").put("data", null);
        }
        HashMap<String, Object> checkGoodInfoImages = new HashMap<>();
        HashMap<String, Object> checkGoodsInfo = new HashMap<>();
        String checkGoodsImages = entity.getGoodsImages();
        String[] split = checkGoodsImages.split(";");
        String url = "https://test-wanghanbin.oss-cn-hangzhou.aliyuncs.com/feiyuImages/";
        for (int j = 0; j < split.length; j++) {
            checkGoodInfoImages.put("goodImage_" + (j + 1), url + split[j]);
        }
        Integer tagId = entity.getGoodsTagId();
        DictGoodsEntity tag = dictGoodsService.getById(tagId);
        Integer shopId = entity.getShopId();
        ShopEntity shopEntity = shopService.getById(shopId);
        checkGoodsInfo.put("checkGoodsId", entity.getCheckGoodsId());
        checkGoodsInfo.put("goodsId", entity.getGoodsId());
        checkGoodsInfo.put("goodsName", entity.getGoodsName());
        checkGoodsInfo.put("goodsIntro", entity.getGoodsIntro());
        checkGoodsInfo.put("shopId", entity.getShopId());
        checkGoodsInfo.put("shopName", shopEntity.getShopName());
        checkGoodsInfo.put("goodsImages", checkGoodInfoImages);
        checkGoodsInfo.put("goodsLicense", entity.getGoodsLicense());
        checkGoodsInfo.put("goodsRent", entity.getGoodsRent());
        checkGoodsInfo.put("goodsDeposit", entity.getGoodsDeposit());
        checkGoodsInfo.put("goodsPrice", entity.getGoodsPrice());
        checkGoodsInfo.put("goodsTagId", entity.getGoodsTagId());
        checkGoodsInfo.put("goodsTagName", tag.getDictGoodsLable());
        checkGoodsInfo.put("goodsTimeMode", entity.getGoodsTimeMode());
        checkGoodsInfo.put("isAllowedBuy", entity.getIsAllowedBuy());
        checkGoodsInfo.put("goodsPostageMode", entity.getGoodsPostageMode());
        checkGoodsInfo.put("goodsMaxRenewalTime", entity.getGoodsMaxRenewalTime());
        checkGoodsInfo.put("goodsNums", entity.getGoodsNums());
        checkGoodsInfo.put("checkGoodsApplyTime", entity.getCheckGoodsApplyTime());
        checkGoodsInfo.put("checkState", entity.getCheckState());
        checkGoodsInfo.put("checkUserId", entity.getCheckUserId());
        checkGoodsInfo.put("checkTime", entity.getCheckTime());
        checkGoodsInfo.put("checkRe", entity.getCheckRe());
        return R.ok("操作成功").put("data", checkGoodsInfo);
    }
}
